
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_EBAS_GRUPPE_EBAS_EJERFORHOLD]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[EBAS_GRUPPE] DROP CONSTRAINT FK_EBAS_GRUPPE_EBAS_EJERFORHOLD
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[EBAS_EJERFORHOLD]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[EBAS_EJERFORHOLD]
GO

CREATE TABLE [dbo].[EBAS_EJERFORHOLD] (
	[GUID] [uniqueidentifier] ROWGUIDCOL NOT NULL ,
	[LEDER] [varchar] (255) COLLATE Danish_Norwegian_CI_AS NOT NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[EBAS_EJERFORHOLD] WITH NOCHECK ADD 
	CONSTRAINT [PK_EBAS_EJERFORHOLD] PRIMARY KEY  CLUSTERED 
	(
		[GUID]
	)  ON [PRIMARY] 
GO

DECLARE 
	@guid uniqueidentifier
SET @guid = newid()	
INSERT INTO EBAS_EJERFORHOLD (GUID, LEDER) VALUES (@guid,'Leif Bergmann')

INSERT INTO EBAS_ADRESSE
SELECT 	NEWID(), 'Henley MBA Denmark', 'Hans Broges gade 2', 
	P.GUID, '70105005', '', 'mba@henley.dk', 
	@guid, T.GUID
FROM	EBAS_POST_NR P, EBAS_ADRESSE_TYPE T
WHERE 	P.POST_NR = '8000'
AND	T.TYPE = 'Firma'
GO
